<template>
	<view class="wrap">
		<ErrDialog v-if="errDialogOpen" ref="errDialog" :dialogData="dialogData" @retryFunciton="retryFunciton">
		</ErrDialog>
		<!-- <u-tabs :list="list" :current="current" @change="change"></u-tabs> -->
		<view v-if="current === 0" style="padding-bottom: 140rpx;">
			<view class="example-body">
				<u-form>
				<u-form-item label="货架" label-width="170">
					<u-input
					class="my-input"
					  @click="changeScanInput('form.huojno')"
					 v-model="form.huojno" style="margin-right: 10rpx;"
					 placeholder="请选择货架编号" ></u-input>
					<u-button @click="scan1('huojno')">扫描</u-button>
				</u-form-item>
				<u-form-item label="货位" label-width="170">
					<u-input
					class="my-input"
					@click="changeScanInput('form.location')"
					v-model="form.location"
					 placeholder="请选择货位"
					 style="margin-right: 10rpx;"></u-input>
					<u-button @click="scan1('location')">扫描</u-button>
				</u-form-item>
				<u-form-item label="移入点位" label-width="170">
					<u-input
					class="my-input"
					@click="changeScanInput('form.landpoint')"
					placeholder="请选择点位"
					v-model="form.landpoint" style="margin-right: 10rpx;"></u-input>
					<u-button @click="scan1('landpoint')">扫描</u-button>
				</u-form-item>


				<!-- <u-form-item label="库房" label-width="170">
					<uni-data-select @showSelector="showSelector($event)" placeholder="请选择库房" v-model="form.kuf_no"
						:localdata="kufList" @change="changeKuf"></uni-data-select>
				</u-form-item>
				<u-form-item label="区域" label-width="170">
					<uni-data-select @showSelector="showSelector($event)" placeholder="请选择区域" :disabled="notChangeQuyNo"
						v-model="form.quy_no" :localdata="quNoList" @change="changeQuyNo"></uni-data-select>
				</u-form-item>
				<u-form-item label="库存状态" label-width="170">
					<uni-data-select @showSelector="showSelector($event)"  placeholder="请选择状态"
						v-model="form.gdstatus" :localdata="gdstatusList" @change="changeGdstatus"></uni-data-select>
				</u-form-item> -->
				<view v-show="showHeight" style="margin: 460rpx;"></view>
				</u-form>
			</view>
			<!-- <view class="search">
				<u-search input-align="center" height="70" v-model="goods" placeholder="请输入商品信息"
					@custom='searchHz'></u-search>
			</view> -->
			<!-- <u-empty v-if="!hzList.length" text="无明细数据,请尝试不同的搜索条件进行搜索" mode="page"></u-empty>

			<u-card v-for="(item, index) in hzList" class="task-list-item" :border="false" padding="20" margin="20rpx"
				@click="goTo(item,index)">
				<view slot="head" style="display: flex;align-items: center;justify-content: space-between;">
					<view style="display: flex;align-items: center;font-size: 30rpx;">
						{{index+1}}.货位：{{item.LOCATION}}
					</view>
					<view style="color: #999999;font-size: 22rpx;">{{item.YEZ_NAME}}/{{item.YEZ_ID}}</view>
				</view>
				<view class="" slot="body">
					<u-row gutter="16">
						<u-col span="12">
							<view class="apply-text"><span>商品：</span>{{item.GDNAME}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>编号：</span>{{item.GDSEQ}}</view>
						</u-col>
						<u-col span="12">
							<view class="apply-text"><span>数量：</span>{{item.AMOUNT}}</view>
						</u-col>
					</u-row>
				</view>

			</u-card>
			<u-loadmore :status="status" /> -->
			<u-row gutter="32" class="more-bottom-box" justify="center">
				<!-- <u-col span="10">
					<view>
						<u-button class="more-button" type="" shape="circle" @click="scan1('tpbar')">扫托盘号</u-button>
					</view>
				</u-col> -->
				<!-- <u-col span="10">
					<view>
						<u-button class="more-button"
						type="primary" shape="circle"
						@click="searchHz">搜索</u-button>
					</view>
				</u-col> -->
				<!-- <u-col span="10">
					<view>
						<u-button class="more-button"
						type="primary" shape="circle"
						@click="searchHz">搜索</u-button>
					</view>
				</u-col> -->
				<u-col span="10">
					<view>
						<u-button class="more-button" type="primary" shape="circle"
							@click="submitShelfMove()">提交</u-button>
					</view>
				</u-col>

				<!-- <u-col span="10">
					<view><u-button class="more-button" type="primary" shape="circle" @click="submitIn">下架</u-button>
					</view>
				</u-col> -->

			</u-row>
		</view>
		<view v-if="current === 1" class="example-body" style="padding-bottom: 140rpx;">


		</view>
		<u-row v-if="current === 1" gutter="32" class="more-bottom-box" justify="center">
			<u-col span="10">
				<view><u-button :disabled="!bsAmount.length" class="more-button" type="primary" shape="circle"
						@click="submitBs('returnSearch')">提交并返回货位列表</u-button>
				</view>
			</u-col>
			<!-- <u-col span="10">
				<view><u-button :disabled="!bsAmount.length" class="more-button" type="primary" shape="circle"
						@click="submitBs()">提交报损</u-button>
				</view>
			</u-col> -->
		</u-row>
		</view>
</template>
<script>
	import ErrDialog from '@/components/err-dialog.vue'
	export default {
		components: {
			ErrDialog
		},

		data() {
			return {
				// 给一个初始值
				scanInput: '',
				scanResult: '',
				notChangeQuyNo: true,
				form: {
					kuf_no: '',
					quy_no: '',
					gztid: '',
					tpNum: '1',
					//1：空托入库2：空托出库
					czlx: '1',
					landpoint: 'DHJ01',
					tpbar: '',
					gdseq: '',
					gdstatus: '',
					yez_id: '',


					huojno: '',
					location: '',
					landpoint: '',

				},
				errDialogOpen: false,
				// 提示信息
				dialogData: {
					title: '出库',
					msgType: '',
					errContent: '',
					confirmText: '',
					functionName: '',
					cancelText: '',
					closeFunction: '',
				},
				//是否为正常物料
				ISZCGD: '',
				keywords: '',
				// form: {
				// 	huoz_id: '',
				// 	tpbar: '',
				// 	itm: '',
				// 	rwid: '',
				// },
				border: true,
				show: false,
				//库房展示
				kufShow: false,

				// 工作台下拉展示
				gzzShow: false,
				// 当前工作台中文
				gztNowLabel: '',
				GZTID: '',

				// 被选中的商品明细下标
				selectItemIndex: '',
				// 托盘的商品明细
				// huojGoodsList: [],
				// 货架上的货位商品明细
				huojGoodsList: [],
				//选中的明细
				SEQNO: '',
				// 选中的货架号
				HUOJNO: '',
				//选中的货架面
				ORIENTATIONS: '',
				//当前选中的托盘号
				tpbar: '',
				kuf: '',
				// 商品相关条件
				goods: '',
				gdstatusList: [{
					text: '合格',
					value: '1'
				}, {
					text: '不合格',
					value: '2'
				}, {
					text: '待检',
					value: '3'
				}, {
					text: '冻结',
					value: '4'
				}, {
					text: '虚拟',
					value: '5'
				}, {
					text: '停售',
					value: '6'
				}, {
					text: '异常',
					value: '7'
				}, {
					text: '国药',
					value: '00'
				}],
				//库房
				kufList: [],
				//区域
				quNoList: [],
				//库别
				kubList: [],
				//工作台
				gztList: [],
				//日历选择显示
				calendaShow: false,
				//有效期日历显示
				calendaEffdateShow: false,
				list: [{
					name: '明细筛选'
				}, {
					name: '明细总览',
				}],

				m2mSimflowList: [],
				m2mOrderFlowList: [],
				current: 0,
				result1: '',
				status: 'nomore',
				iconType: 'circle',
				isDot: false,
				loadText: {
					loadmore: '点击加载更多',
					loading: '正在加载...',
					nomore: '没有更多了'
				},
				// 搜索栏的托盘号
				tpbar: '',
				nvueWidth: 730,
				only_one: [{
					text: '选择此项',
					value: 0
				}],
				// 基础表单数据
				baseFormData: {
					name: '',
					age: '',
					introduction: '',
					sex: 2,
					hobby: [5],
					datetimesingle: 1627529992399
				},
				// 汇总信息存储
				hzData: {

				},
				// 点击的汇总下标
				hzIndex: '',
				refreshInHead: true,
				refreshMxMsg: true,
				hzList: [],
				showHeight: false,
				oneMx: {},
				disableTrue: true,
				// 入库点
				landpoint: '',
				sjAmouont: '1',
				sjLocation: '',
				// 报损数量
				bsAmount: '',
			}
		},
		// 该写提交盘点单了 接口7
		onUnload() {
			// 移除监听事件
			uni.$off('scancodedate')
		},
		onLoad() {
			//激光扫描监听事件
			var _this = this
			uni.$on("scancodedate", async (res) => {
				console.log("货架移位页面监听到的async:" + res); //我是全局事件订阅的调用方法
				_this.scanResult = JSON.stringify(res);
				setTimeout(() => {
					_this.changeScanValue()
				}, 20);


			})

			this.form.kuf_no = uni.getStorageSync("reporting-losses-kuf_no")

			this.form.quy_no = uni.getStorageSync("reporting-losses-quy_no")

			this.form.gdstatus = uni.getStorageSync('reporting-losses-gdstatus')
		},


		created() {
			this.getKuf(2)
			this.getKuf(3)
			// this.getGzt()
			// this.init()
			this.searchHz()
		},
		// 数据变化适用
		onShow() {
			this.myShow()

		},
		onBackPress() {
			console.log("点击了返回")
			uni.switchTab({
				url: "/pages/sys/workbench/wms-work"
			})
			return true
		},
		methods: {
// 判定点击的哪个输入框
			changeScanInput(inputItem) {
				console.log(inputItem)
				this.scanInput = inputItem
				//this.$u.toast(JSON.stringify(inputItem))
			},
			// 扫描后执行的方法,判断输入框并绑定值,可以自行跳转,或者扫描完执行某方法,
			changeScanValue() {
				let scanInput = this.scanInput
				let result = JSON.parse(this.scanResult)
				if ("form.landpoint" === scanInput) {
					console.log("this.form.landpoint")
					this.form.landpoint = result
				} else if("form.huojno" === scanInput){
					this.form.huojno = result
				} else if("form.location" === scanInput){
					this.form.location = result
				}else {
					// this.$u.toast('没有预先适配:' + scanInput)
					console.log('没有预先适配:' + scanInput)
				}
			},
			// 下拉内容是否展开
			showSelector(res) {
				console.log(res)
				this.showHeight = res
			},
			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				console.log(e);
				this.selectItemIndex = e
			},
			// 选中任一radio时，由radio-group触发
			radioGroupChange(e) {
				console.log("SEQNO:" + this.SEQNO)
				console.log("radioGroupChange:" + e);
				this.oneMx = this.huojGoodsList[e]
				console.log("单选选择的明细:" + JSON.stringify(this.oneMx))
			},
			navTo(url) {
				// uni.navigateTo({
				// 	url: url
				// });
				// uni.switchTab({
				// 	url: url
				// });
				uni.switchTab({
					url: url,
					success: function(e) {
						var page = getCurrentPages().pop(); // 返回页面数组的最后一个页面数据
						if (page == undefined || page == null)
							return; //如果最后一个页面为undefined或null，即当前就在首页 return出去，不调用onLoad
						page.onLoad();
					}
				});


			},
			searchHz() {
				// this.getInListOneInfo()
				// this.getOutTpbarList()
				// this.getCheckList()
				// this.getCheckList()
				// this.getLocationList()
				this.getHzList()
			},
			overStyle(over) {
				if (over) {
					return "text-align: right;color: #58ca93;";
				} else {
					return "text-align: right;color: #f28c03;";
				}
			},
			init() {
				this.GZTID = uni.getStorageSync('IN_GZTID')
				this.kuf = uni.getStorageSync('kuf')
			},
			goTo(item, index) {
				if (item.over) {
					this.$u.toast('已完成')
					return
				} else {
					let item = this.hzList[index]
					this.oneMx = item
					// this.hzData = item
					// this.hzIndex = index
					// this.getLocationMxList(item)
					// console.log('item:' + JSON.stringify(item))
					// item.index = Number(index + 1)
					// this.oneMx = item
					// tabs转换到第一个
					this.change(1)
				}

				// let id = item.INPAGENO
				// uni.navigateTo({
				// 	url: 'index?item=' + JSON.stringify(item)
				// });
			},
			// 根据货架号和货架面获取货位数据
			getOutInfoByTpbar() {
				// 1、IV\_USER\_ID 用户编号,
				// 2、IV\_HUOJNO 货架号
				// 3、IV\_ORIENTATIONS 货架朝面

				const USER_ID = uni.getStorageSync('USER_ID')
				const GZTID = this.HUOJNO ? this.HUOJNO : "%"
				const ORIENTATIONS = this.ORIENTATIONS ? this.ORIENTATIONS : "%"

				let param = USER_ID + "," + GZTID + "," + ORIENTATIONS;
				console.log("iv_parm:" + param)
				this.$u.api.general({
						iv_code: "GETSTOCKHJ",
						iv_parm: param
					})
					.then(res => {
						// console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("返回的data:" + JSON.stringify(data))
						if (res.success) {
							this.huojGoodsList = data
							// 默认选中第一个
							this.SEQNO = data[0].SEQNO
							this.oneMx = data[0]
							//是否新批次出库第一托
							// this.isFirshOut()
							// this.hzData = data[0]
							// if (this.list.length < 1) {
							// 	this.$u.toast("没有查到数据");
							// }
						} else {
							this.$u.toast(res.msg);
						}
					});
			},
			// // 根据托盘号,获取出库商品明细集合   返回集合后,获取到物料号后,询问第一个物料
			// getOutInfoByTpbar() {
			// 	//1、IV\_STAFF 用户id
			// 	// 2、IV\_GZTID 工作站
			// 	// 3、IV\_BARCODE 托盘号，单号

			// 	const USER_ID = uni.getStorageSync('USER_ID')
			// 	const GZTID = this.GZTID ? this.GZTID : "%"
			// 	const tpbar = this.tpbar ? this.tpbar : "%"

			// 	let param = USER_ID + "," + GZTID + "," + tpbar;
			// 	console.log("iv_parm:" + param)
			// 	this.$u.api.general({
			// 			iv_code: "PDAOUTTPBARMX",
			// 			iv_parm: param
			// 		})
			// 		.then(res => {
			// 			// console.log("返回的res:" + JSON.stringify(res))
			// 			let data = res.data
			// 			console.log("返回的data:" + JSON.stringify(data))
			// 			if (res.success) {
			// 				this.huojGoodsList = data
			// 				// 默认选中第一个
			// 				this.SEQNO = data[0].SEQNO
			// 				this.oneMx = data[0]
			// 				//是否新批次出库第一托
			// 				// this.isFirshOut()
			// 				// this.hzData = data[0]
			// 				// if (this.list.length < 1) {
			// 				// 	this.$u.toast("没有查到数据");
			// 				// }
			// 			} else {
			// 				this.$u.toast(res.msg);
			// 			}
			// 		});
			// },
			getKuf(type) {
				const USER_ID = uni.getStorageSync('USER_ID')
				const KUB = '%'
				const KUF_NO = "%"
				// if(type == "3"){
				// 	KUF_NO = this.form.kuf_no ? this.form.kuf_no : '%'
				// }
				//1获取库别，2获取库房，3获取区域
				const GET_TYPE = type
				let param = USER_ID + "," + KUB + "," + KUF_NO + "," + GET_TYPE;
				this.$u.api.general({
						iv_code: "GETKUFQUYNO",
						iv_parm: param
					})
					.then(res => {
						// console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("kuf返回的data:" + JSON.stringify(data))
						console.log("type:" + type)
						if (res.success) {
							//补充text
							// this.kufList = data
							console.log("type:" + type)
							if (type == "2") {
								this.kufList = data.map(v => {
									this.$set(v, 'text', v.KUF_NO)
									this.$set(v, 'value', v.KUF_NO)
									return v
								})
								// console.log("this.kufList:"+JSON.stringify(this.kufList))
							} else if (type == "3") {
								this.quNoList = data.map(v => {
									this.$set(v, 'text', v.QUY_NO)
									this.$set(v, 'value', v.QUY_NO)
									return v
								})
							} else {
								this.kubList = data.map(v => {
									this.$set(v, 'text', v.KUB)
									this.$set(v, 'value', v.KUB)
									return v
								})
							}

						} else {
							this.errContent = res.msg
							this.$u.toast(res.msg);
						}
					});
			},
			// 是否新批次出库第一托?
			isFirshOut() {
				// 1、IV\_STAFF 用户id
				// 2、IV\_GOODSID 商品id
				// 3、IV\_ITEMID 批次
				// 4、IV\_BATCHNO 批号
				// 5、IV\_OUT\_LX 出库场景类型
				// 6、IV\_CKJH 出库下发：1，拣货2
				const USER_ID = uni.getStorageSync('USER_ID')

				const GOODSID = this.oneMx.GOODSID ? this.oneMx.GOODSID : "%"
				const ITEMID = this.oneMx.ITEMID ? this.oneMx.ITEMID : "%"
				const BATCHNO = this.oneMx.BATCHNO ? this.oneMx.BATCHNO : "%"
				const OUT_LX = this.oneMx.OUTTYPE ? this.oneMx.OUTTYPE : "%"
				const CKJH = 2
				let param = USER_ID + "," + GOODSID + "," + ITEMID + "," +
					BATCHNO + "," + OUT_LX + "," + CKJH;
				console.log("iv_parm:" + param)
				this.$u.api.general({
						iv_code: "PDAGETFIRSTOUTFLG",
						iv_parm: param
					})
					.then(res => {
						// console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("返回的data:" + JSON.stringify(data))
						if (res.success) {
							// this.hzData = data[0]
							// if (this.list.length < 1) {
							// 	this.$u.toast("没有查到数据");
							// }

							// 如果是第一次出库,进行提示
							if (data.ISFIRSTOUT == 'Y') {
								this.dialogData = {
									title: '出库检测(第一托?)',
									msgType: 'warn',
									errContent: '本明细是新批次出库第一托',
									confirmText: '继续进行出库(判断是否为正常物料)',
									// 如果选右边的执行的返回方法
									functionName: 'isNarmalGoods',
									cancelText: '关闭',
								}
								this.errDialogShow()
								this.ISZCGD = data.ISZCGD
								// if(data.ISZCGD=='Y'){
								// 	this.ISZCGD = 'Y'
								// }
							} else {
								this.submitOut()
							}

						} else {
							this.$u.toast(res.msg);
						}
					});
			},
			retryFunciton(e) {
				console.log("子组件返回的e:" + e)
				if (e == "isNarmalGoods") {
					this.isNarmalGoods()
				} else if (e == "submitCheck") {
					this.submitCheck()
				} else if (e == 'getHzList') {
					this.getHzList()
				} else if (e == 'submitBs') {
					this.submitBs()
				} else if (e == 'submitShelfMove') {
					this.submitShelfMove()
				} else {

				}
			},
			// 是否是
			isNarmalGoods() {
				if (this.ISZCGD == 'Y') {
					// (对应PDA弹窗提醒)
					this.dialogData = {
						title: '出库检测(正常物料?)',
						msgType: 'warn',
						errContent: '本明细是正常物料',
						confirmText: '我知道了',
						// 如果选右边的执行的返回方法
						functionName: 'submitOut',
						cancelText: '关闭',
					}
					this.errDialogShow()
				} else if (this.ISZCGD == 'N') {
					// 对应pda弹窗选择确认
					this.dialogData = {
						title: '出库检测(正常物料?)',
						msgType: 'error',
						errContent: '本明细不是正常物料',
						confirmText: '同意此物料不是正常物料',
						// 如果选右边的执行的返回方法
						functionName: 'submitOut',
						cancelText: '拒绝',
						closeFunction: 'noNormalGoods',

					}
					this.errDialogShow()
				} else {
					this.$u.toast('ISZCGD未知,严重错误,请排查isFirshOut()返回值')
				}
			},
			noNormalGoods() {
				this.$u.toast('点击了否,不同意')
			},
			// // 是正常物料的弹窗提示(权限控制,指定账号弹窗)
			// isToast(){

			// },
			errDialogShow() {
				console.log("刷新显示提示框")
				//刷新显示
				let that = this;
				that.errDialogOpen = false;
				that.$nextTick(() => {
					that.errDialogOpen = true;
				})

			},
			// getInListBytpbar() {
			// 	const STORAGE_ID = uni.getStorageSync('STORAGE_ID')
			// 	const huoz_id = "%"
			// 	const USER_ID = uni.getStorageSync('USER_ID')
			// 	const inbillNumber = this.tpbar ? this.tpbar : "%"

			// 	const unit = "%"
			// 	const goodsId = "%"
			// 	const palletNumber = "%"
			// 	let param = STORAGE_ID + "," + huoz_id + "," + USER_ID + "," +
			// 		inbillNumber + "," + unit + "," + goodsId + "," + palletNumber;
			// 	console.log("iv_parm:" + param)
			// 	this.$u.api.general({
			// 			iv_code: "PDAINBILLINPAGENO",
			// 			iv_parm: param
			// 		})
			// 		.then(res => {
			// 			// console.log("返回的res:" + JSON.stringify(res))
			// 			let data = res.data
			// 			console.log("返回的data:" + JSON.stringify(data))
			// 			if (res.success) {
			// 				this.hzData = data[0]
			// 				// if (this.list.length < 1) {
			// 				// 	this.$u.toast("没有查到数据");
			// 				// }
			// 			} else {
			// 				this.$u.toast(res.msg);
			// 			}
			// 		});
			// },
			//重新加载子组件
			myShow() {

				console.log("this.hzData==>" + JSON.stringify(this.hzData))
				//刷新显示
				let that = this;
				that.refreshInHead = false;
				that.$nextTick(() => {
					that.refreshInHead = true;
				})

			},
			myMxShow() {
				//刷新显示
				let that = this;
				that.refreshMxMsg = false;
				that.$nextTick(() => {
					that.refreshMxMsg = true;
				})

			},

			scan1(param) {
				console.log("扫描")
				// #ifdef H5
				this.$u.toast('H5页面不支持扫码,请用安卓等移动设备重试')
				// #endif
				let that = this;
				// 允许从相机和相册扫码
				uni.scanCode({
					success: function(res) {
						const result = res.result
						if (param == 'huojno') {
							this.form.huojno = result
						} else if (param == 'location') {
							this.form.location = location
						} else if (param == 'landpoint') {
							this.form.landpoint = landpoint
						}

					}
				});
			},
			change(index) {
				console.log(this.current)
				this.current = index;
			},
			submit(index) {
				if (this.tpbar) {
					this.$u.toast('调用下架接口')
				} else {
					this.$u.toast('请补充入库单号的数据')
				}
			},
			// 提交库存报损
			submitBs(paramReturn) {

				// 1、IV_STAFF       职员
				// 2、IV_TYPE_BILL     单据类型
				// 3、IV_STORAGEID     仓库
				// 4、IV_GOODSID      商品id
				// 5、IV_ITEMID      批次
				// 6、IV_BATCHNO       批号
				// 7、IV_LOCATIONID    货位
				// 8、IV_GDSTATUS      质量状态
				// 9、IV_YEW_STATE   业务状态
				// 10、IV_KEEPACCOUNT   保管着
				// 11、IV_CONTAINSNUMBER 内敛数
				// 12、IV_UNIQUECODE     唯一码
				// 13、IV_TPBAR       托盘
				// 14、 IN_AMOUNT       库存数量
				// 15、IN_AMOUNT_NEW     新数量
				// 16、IV_CLTYPE    处理表示  ‘Y’

				console.log("oneMx=>" + JSON.stringify(this.oneMx))
				const USER_ID = uni.getStorageSync('USER_ID')
				const TYPE_BILL = "1"
				//this.oneMx.TYPE_BILL ? this.oneMx.TYPE_BILL : "%"
				const STORAGEID = this.oneMx.STORAGEID ? this.oneMx.STORAGEID : "%"
				const GOODSID = this.oneMx.GOODSID ? this.oneMx.GOODSID : "%"
				const ITEMID = this.oneMx.ITEMID ? this.oneMx.ITEMID : "%"

				const BATCHNO = this.oneMx.BATCHNO ? this.oneMx.BATCHNO : "%"
				const LOCATIONID = this.oneMx.LOCATIONID ? this.oneMx.LOCATIONID : "%"
				const GDSTATUS = this.oneMx.GDSTATUS ? this.oneMx.GDSTATUS : "%"
				const YEW_STATE = this.oneMx.YEW_STATE ? this.oneMx.YEW_STATE : "%"

				const KEEPACCOUNT = this.oneMx.KEEPACCOUNT ? this.oneMx.KEEPACCOUNT : "%"
				const CONTAINSNUMBER = this.oneMx.CONTAINSNUMBER ? this.oneMx.CONTAINSNUMBER : "%"
				const UNIQUECODE = this.oneMx.UNIQUECODE ? this.oneMx.UNIQUECODE : "%"
				const TPBAR = this.oneMx.TPBAR ? this.oneMx.TPBAR : '%'
				const AMOUNT = this.oneMx.AMOUNT ? this.oneMx.AMOUNT : '%'
				if (this.bsAmount < 1) {
					this.$u.toast('库存报损数量不可以小于1')
					return
				}
				const AMOUNT_NEW = Number(this.oneMx.AMOUNT - this.bsAmount)

				const CLTYPE = 'Y'



				let param = USER_ID + "," +
					TYPE_BILL + "," +
					STORAGEID + "," +
					GOODSID + "," +
					ITEMID + "," +

					BATCHNO + "," +
					LOCATIONID + "," +
					GDSTATUS + "," +
					YEW_STATE + "," +

					KEEPACCOUNT + "," +
					CONTAINSNUMBER + "," +
					UNIQUECODE + "," +
					TPBAR + "," +
					AMOUNT + "," +
					AMOUNT_NEW + "," +
					CLTYPE;

				console.log("iv_parm:" + param + ";")
				let that = this
				this.$u.api.prcutlexecvar({
						iv_code: "PDAKCTZBILLCRT",
						iv_parm: param,
						ov_var1: '2',
						ov_var2: '2',
						ov_var3: '2',
						ov_var4: '2',
						ov_var5: '2',
					})
					.then(res => {
						console.log("返回的res:" + JSON.stringify(res))
						if (res.success) {
							that.$u.toast(res.msg);
							let data = res.data
							// console.log("返回的data:" + JSON.stringify(data))
							console.log("返回的res.msg:" + res.msg)
							this.submitSuccess()
							if (paramReturn == "returnSearch") {
								this.current = 0
							}
						} else {
							this.dialogData = {
								title: '库存报损',
								msgType: 'error',
								errContent: res.msg,
								confirmText: '重新提交',
								// 如果选右边的执行的返回方法
								functionName: 'submitBs',
								cancelText: '关闭',
								closeFunction: '',
							}
							this.errDialogShow()
						}

					});
			},

			submitQualityRelease(paramReturn) {

				// 1、IV_STAFF 人员
				// 2、IV_TYPE_BILL 单据类型
				// 3、IV_STORAGEID 仓库
				// 4、IV_GOODSID 商品
				// 新增，IV_ITEMID 批次
				// 5、IV_BATCHNO 批号
				// 6、IV_LOCATIONID 货位id
				// 7、IV_GDSTATUS 库存状态
				// 8、IV_YEW_STATE业务状态
				// 9、IV_KEEPACCOUNT 保管账
				// 10、IV_CONTAINSNUMBER 内联数
				// 11、IV_UNIQUECODE     唯一码
				// 12、IV_TPBAR         托盘号
				// 13、IN_AMOUNT         数量
				// 14、IV_GDSTATUS_MD    目的状态
				// 15、IV_CLTYPE  操作类型

				console.log("oneMx=>" + JSON.stringify(this.oneMx))
				const USER_ID = uni.getStorageSync('USER_ID')
				const TYPE_BILL = "KN07"
				//this.oneMx.TYPE_BILL ? this.oneMx.TYPE_BILL : "%"
				const STORAGEID = this.oneMx.STORAGEID ? this.oneMx.STORAGEID : "%"
				const GOODSID = this.oneMx.GOODSID ? this.oneMx.GOODSID : "%"
				const ITEMID = this.oneMx.ITEMID ? this.oneMx.ITEMID : "%"

				const BATCHNO = this.oneMx.BATCHNO ? this.oneMx.BATCHNO : "%"
				const LOCATIONID = this.oneMx.LOCATIONID ? this.oneMx.LOCATIONID : "%"
				const GDSTATUS = this.oneMx.GDSTATUS ? this.oneMx.GDSTATUS : "%"
				const YEW_STATE = this.oneMx.YEW_STATE ? this.oneMx.YEW_STATE : "%"

				const KEEPACCOUNT = this.oneMx.KEEPACCOUNT ? this.oneMx.KEEPACCOUNT : "%"
				const CONTAINSNUMBER = this.oneMx.CONTAINSNUMBER ? this.oneMx.CONTAINSNUMBER : "%"
				const UNIQUECODE = this.oneMx.UNIQUECODE ? this.oneMx.UNIQUECODE : "%"
				const TPBAR = this.oneMx.TPBAR ? this.oneMx.TPBAR : '%'
				const AMOUNT = this.oneMx.AMOUNT ? this.oneMx.AMOUNT : '%'
				const GDSTATUS_MD = 1
				const CLTYPE = 'Y'



				let param = USER_ID + "," +
					TYPE_BILL + "," +
					STORAGEID + "," +
					GOODSID + "," +
					ITEMID + "," +

					BATCHNO + "," +
					LOCATIONID + "," +
					GDSTATUS + "," +
					YEW_STATE + "," +

					KEEPACCOUNT + "," +
					CONTAINSNUMBER + "," +
					UNIQUECODE + "," +
					TPBAR + "," +
					AMOUNT + "," +
					GDSTATUS_MD + "," +
					CLTYPE;

				console.log("iv_parm:" + param + ";")
				let that = this
				this.$u.api.prcutlexecvar({
						iv_code: "CRTKCBHBILL",
						iv_parm: param,
						ov_var1: '2',
						ov_var2: '2',
						ov_var3: '2',
						ov_var4: '2',
						ov_var5: '2',
					})
					.then(res => {
						console.log("返回的res:" + JSON.stringify(res))
						if (res.success) {
							that.$u.toast(res.msg);
							let data = res.data
							// console.log("返回的data:" + JSON.stringify(data))
							console.log("返回的res.msg:" + res.msg)
							this.submitSuccess()
							if (paramReturn == "returnSearch") {
								this.current = 0
							}
						} else {
							this.dialogData = {
								title: '质量检测',
								msgType: 'error',
								errContent: res.msg,
								confirmText: '重新提交',
								// 如果选右边的执行的返回方法
								functionName: 'submitQualityRelease',
								cancelText: '关闭',
								closeFunction: '',
							}
							this.errDialogShow()
						}

					});
			},
			submitShelfMove(paramReturn) {


				// 1、IV_HUOJNO 货架
				// 2、IV_LOCATION 货位
				// 3、IV_KUF_NO_T 目的库房
				// 4、IV_QUY_NO_T 目的库区
				// 5、IV_STAFF 人员
				// 6、IV_LANDPOINT_T 移入点位

				// console.log("oneMx=>" + JSON.stringify(this.oneMx))
				const HUOJNO = this.form.huojno ? this.form.huojno : "%"
				const LOCATION = this.form.location ? this.form.location : "%"
				const KUF_NO_T = '%'
				const QUY_NO_T = '%'
				const STAFF = uni.getStorageSync('USER_ID')
				const LANDPOINT_T = this.form.landpoint ? this.form.landpoint : "%"


				let param = HUOJNO + "," +
					LOCATION + "," +
					KUF_NO_T + "," +
					QUY_NO_T + "," +
					STAFF + "," +
					LANDPOINT_T;

				console.log("iv_parm:" + param + ";")
				let that = this
				this.$u.api.prcutlexecvar({
						iv_code: "CRTHUOJMOVE",
						iv_parm: param,
						ov_var1: '2',
						ov_var2: '2',
						ov_var3: '2',
						ov_var4: '2',
						ov_var5: '2',
					})
					.then(res => {
						console.log("返回的res:" + JSON.stringify(res))
						if (res.success) {
							that.$u.toast(res.msg);
							let data = res.data
							// console.log("返回的data:" + JSON.stringify(data))
							console.log("返回的res.msg:" + res.msg)
							this.submitSuccess()
							if (paramReturn == "returnSearch") {
								this.current = 0
							}
						} else {
							this.dialogData = {
								title: '提交货架移位',
								msgType: 'error',
								errContent: res.msg,
								confirmText: '重新提交',
								// 如果选右边的执行的返回方法
								functionName: 'submitShelfMove',
								cancelText: '关闭',
								closeFunction: '',
							}
							this.errDialogShow()
						}

					});
			},
			submitCheck(paramReturn) {


				// 1、IV\_STAFF 人员
				// 2、IV\_PDNO 盘点单号
				// 3、IN\_SORTSN 行号
				// 4、IV\_JS 件数
				// 5、IV\_LSS 零散数
				// 6、IN\_AMOUNT 实盘数量

				console.log("oneMx=>" + JSON.stringify(this.oneMx))
				const USER_ID = uni.getStorageSync('USER_ID')
				const PDNO = this.oneMx.PDNO ? this.oneMx.PDNO : "%"
				const SORTSN = this.oneMx.SORTSN ? this.oneMx.SORTSN : "%"
				const JS = 0
				const LSS = this.oneMx.AMOUNT ? this.oneMx.AMOUNT : "0"
				const AMOUNT = this.oneMx.AMOUNT ? this.oneMx.AMOUNT : "0"


				let param = USER_ID + "," +
					PDNO + "," +
					SORTSN + "," +
					JS + "," +
					LSS + "," +
					AMOUNT;

				console.log("iv_parm:" + param + ";")
				let that = this
				this.$u.api.prcutlexecvar({
						iv_code: "PDRWQR",
						iv_parm: param,
						ov_var1: '2',
						ov_var2: '2',
						ov_var3: '2',
						ov_var4: '2',
						ov_var5: '2',
					})
					.then(res => {
						console.log("返回的res:" + JSON.stringify(res))
						that.$u.toast(res.msg);
						if (res.success) {

							let data = res.data
							// console.log("返回的data:" + JSON.stringify(data))
							console.log("返回的res.msg:" + res.msg)
							this.submitSuccess()
							if (paramReturn == "returnSearch") {
								this.current = 0
							}
						} else {
							this.dialogData = {
								title: '盘点提交',
								msgType: 'error',
								errContent: res.msg,
								confirmText: '重新提交',
								// 如果选右边的执行的返回方法
								functionName: 'submitCheck',
								cancelText: '关闭',
								closeFunction: '',
							}
							this.errDialogShow()
						}

					});
			},
			submitOutBefore() {
				//是否新批次出库第一托
				this.isFirshOut()
			},
			submitSuccess() {
				// this.huojGoodsList = []
				// this.bsAmount = ''
				// this.oneMx = {}
				// this.searchHz()
				this.form = {
					kuf_no: '',
					quy_no: '',
					gztid: '',
					tpNum: '1',
					//1：空托入库2：空托出库
					czlx: '1',
					landpoint: 'DHJ01',
					tpbar: '',
					gdseq: '',
					gdstatus: '',
					yez_id: '',


					huojno: '',
					location: '',
					landpoint: '',

				}
			},
			navTo(url) {
				uni.navigateTo({
					url: url
				});
			},
			// 根据货位进行搜索缓存区待拣货库存
			getLocationMxList(item) {
				// 2、IV_LOCATIONID 货位

				const locationid = item.LOCATIONID

				let param = locationid;

				console.log("iv_parm:" + param)
				let that = this
				this.$u.api.general({
						iv_code: "PDAGETZJHWSTOCK",
						iv_parm: param
					})
					.then(res => {
						// console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("返回的data:" + JSON.stringify(data))
						if (res.success) {
							if (data.length < 1) {
								this.$u.toast('暂无数据')
							}
							//补充text
							this.huojGoodsList = data
							this.oneMx = this.huojGoodsList[0]

							this.status = 'nomore';
						} else {
							this.$u.toast(res.msg);
						}
					});
			},
			// 根据货位进行搜索
			// getLocationMxList(item) {

			// 	// 1、IV\_STAFF 人员
			// 	// 2、IV_LOCATIONID 货位
			// 	const USER_ID = uni.getStorageSync('USER_ID')
			// 	const locationid = item.LOCATIONID

			// 	let param = USER_ID + "," + locationid;

			// 	console.log("iv_parm:" + param)
			// 	let that = this
			// 	this.$u.api.general({
			// 			iv_code: "GETPDHWDETAILDISP",
			// 			iv_parm: param
			// 		})
			// 		.then(res => {
			// 			// console.log("返回的res:" + JSON.stringify(res))
			// 			let data = res.data
			// 			console.log("返回的data:" + JSON.stringify(data))
			// 			if (res.success) {
			// 				//补充text
			// 				this.huojGoodsList = data
			// 				this.oneMx = this.huojGoodsList[0]

			// 				this.status = 'nomore';
			// 			} else {
			// 				this.$u.toast(res.msg);
			// 			}
			// 		});
			// },
			// 获取库存信息
			getHzList() {
				// 1、IV\_STORAGEID 仓库可以传%
				// 2、IV\_YEZ\_ID 业主id 可以传%
				// 3、IV\_USER\_ID 用户id,
				// 4、IV_KUF_NO 库房
				// 5、IV_QUY_NO 区域
				// 6、IV\_LOCATION 货位信息（货位信息，可以传%）
				// 7、IV\_GDTJ 商品信息（gdseq,69码，助记码）
				// 8、IV_GDSTATUS  库存状态
				const STORAGEID = uni.getStorageSync("STORAGE_ID");
				const YEZ_ID = this.form.yez_id ? this.form.yez_id : '%'
				const USER_ID = uni.getStorageSync("USER_ID");


				const kuf_no = this.form.kuf_no ? this.form.kuf_no : '%'
				const quyu_no = this.form.quyu_no ? this.form.quyu_no : '%'
				const LOCATION = '%'
				const GDTJ = '%'
				const GDSTATUS = this.form.gdstatus ? this.form.gdstatus : "%"


				let param = STORAGEID + "," +
					YEZ_ID + "," +
					USER_ID + "," +

					kuf_no + "," +
					quyu_no + "," +
					LOCATION + "," +
					GDTJ + "," +
					GDSTATUS

				console.log("iv_parm:" + param)
				let that = this
				this.$u.api.general({
						iv_code: "GETSTOCKKN",
						iv_parm: param
					})
					.then(res => {
						console.log("返回的res:" + JSON.stringify(res))
						if (res.success) {
							let data = res.data
							console.log("返回的data:" + JSON.stringify(data))
							//补充text
							this.hzList = data
							if (this.hzList.length < 1) {
								this.$u.toast("暂无数据");
							}
							this.status = 'nomore';
						} else {

							this.dialogData = {
								title: '库存报损查询',
								msgType: 'error',
								errContent: res.msg,
								confirmText: '重试',
								// 如果选右边的执行的返回方法
								functionName: 'getHzList',
								cancelText: '关闭',
								closeFunction: '',
							}
							this.errDialogShow()
						}
					});
			},
			getLocationList() {
				// 1、IV\_KUF\_NO 库房
				// 2、IV\_QUY\_NO 区域
				// 3、IV\_GDSEQ 商品
				const kuf_no = this.form.kuf_no ? this.form.kuf_no : '%'
				const quyu_no = this.form.quyu_no ? this.form.quyu_no : '%'
				const GDSEQ = this.form.gdseq ? this.form.gdseq : "%"
				let param = kuf_no + "," + quyu_no + "," + GDSEQ
				console.log("iv_parm:" + param)
				let that = this
				this.$u.api.general({
						iv_code: "PDAGETZJHW",
						iv_parm: param
					})
					.then(res => {
						// console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("返回的data:" + JSON.stringify(data))
						if (res.success) {
							//补充text
							this.hzList = data
							if (this.hzList.length < 1) {
								this.$u.toast("暂无数据");
							}
							this.status = 'nomore';
						} else {
							this.$u.toast(res.msg);
						}
					});
			},
			// 获取盘点任务列表
			getCheckList() {
				// 1、IV\_STAFF 人员
				// 2、IV\_GZTID 工作台
				// 3、IV\_STORAGEID 仓库
				// 4、IV\_KUF\_NO 库房
				// 5、IV\_QUY\_NO 区域
				const USER_ID = uni.getStorageSync('USER_ID')
				const GZTID = this.GZTID ? this.GZTID : "%"
				const STORAGE_ID = uni.getStorageSync('STORAGE_ID')
				const kuf_no = this.form.kuf_no ? this.form.kuf_no : '%'
				const quyu_no = this.form.quyu_no ? this.form.quyu_no : '%'
				let param = USER_ID + "," + GZTID + "," + STORAGE_ID +
					"," + kuf_no + "," + quyu_no;
				console.log("iv_parm:" + param)
				let that = this
				this.$u.api.general({
						iv_code: "GETPDHWDISP",
						iv_parm: param
					})
					.then(res => {
						// console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("返回的data:" + JSON.stringify(data))
						if (res.success) {
							//补充text
							this.hzList = data
							if (this.hzList.length < 1) {
								this.$u.toast("暂无数据");
							}
							this.status = 'nomore';


						} else {
							this.$u.toast(res.msg);
						}
					});
			},
			getOutTpbarList() {
				// 1、IV\_STAFF 用户id
				// 2、IV\_GZTID 工作站
				// 3、IV\_YEW\_TYPE业务类型2：出库
				// const STORAGE_ID = uni.getStorageSync('STORAGE_ID')
				// // const USER_GH = uni.getStorageSync('USER_GH')
				// const yez_id = this.form.huoz_id ? this.form.huoz_id : "%"
				const USER_ID = uni.getStorageSync('USER_ID')
				const GZTID = this.GZTID ? this.GZTID : "%"
				const yew_type = '2'
				let param = USER_ID + "," + GZTID + "," + yew_type;
				console.log("iv_parm:" + param)
				let that = this
				this.$u.api.general({
						iv_code: "PDAOUTTPBAR",
						iv_parm: param
					})
					.then(res => {
						// console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						// console.log("返回的data:" + JSON.stringify(data))
						if (res.success) {
							//补充text
							this.hzList = data

							this.status = 'nomore';


						} else {
							this.$u.toast(res.msg);
						}
					});
			},

			blurFunction() {
				console.log("失去了焦点")
				this.myMxShow()
			},
			changeProductDate(e) {
				console.log("选择的日期:" + JSON.stringify(e))
				this.oneMx.PRODUCTDATE = e.result
				this.myMxShow()
			},
			changeEFFDATE(e) {
				this.oneMx.EFFDATE = e.result
				this.myMxShow()
			},
			changeGzt(index) {
				// 表层文字
				this.gztNowLabel = this.gztList[index].text;
				uni.setStorageSync('gztNowLabel', this.gztNowLabel)

				// id
				const GZTID = this.gztList[index].GZTID == "%" ? '' : this.gztList[index].GZTID;
				if (GZTID) {
					this.GZTID = GZTID
					uni.setStorageSync('IN_GZTID', GZTID)

				} else {
					this.GZTID = ''
					uni.removeStorageSync('IN_GZTID')
				}
				console.log("缓存中的入库工作站IN_GZTID:" + uni.getStorageSync('IN_GZTID'))

			},
			changeGdstatus(e) {
				this.form.gdstatus = e
				uni.setStorageSync("reporting-losses-gdstatus", e)
				console.log("库存报损缓存库存状态:" + uni.getStorageSync("reporting-losses-gdstatus"))
				this.showHeight = false
			},
			changeQuyNo(e) {
				this.form.quy_no = e
				uni.setStorageSync("reporting-losses-quy_no", e)
				console.log("库存报损页面 缓存区域号:" + uni.getStorageSync("reporting-losses-quy_no"))
				this.showHeight = false
			},
			changeKuf(e) {
				console.log("e:" + e);
				console.log("this.kufList:" + JSON.stringify(this.kufList))
				// const item = this.kufList[e];
				// console.log("item:"+item)
				this.form.kuf_no = e
				console.log(this.form.kuf_no)
				// 判断一下区域是不是在这个库房,如果在,就不更改区域,如果不在,就更改区域
				this.getKufbyKuf()
				this.notChangeQuyNo = e ? false : true

				uni.setStorageSync("reporting-losses-kuf_no", e)
				console.log("质量放行缓存库房号:" + uni.getStorageSync("reporting-losses-kuf_no"))
				this.showHeight = false
			},
			// 查看选择到的库房的区域
			getKufbyKuf() {
				const USER_ID = uni.getStorageSync('USER_ID')
				const KUB = '%'
				const KUF_NO = this.form.kuf_no ? this.form.kuf_no : "%"
				//1获取库别，2获取库房，3获取区域
				const GET_TYPE = 3
				let param = USER_ID + "," + KUB + "," + KUF_NO + "," + GET_TYPE;
				console.log(param)
				this.$u.api.general({
						iv_code: "GETKUFQUYNO",
						iv_parm: param
					})
					.then(res => {
						console.log("getKufbyKuf返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("查看选择到的库房的区域返回的data:" + JSON.stringify(data))
						if (res.success) {

							this.form.quy_no = uni.getStorageSync("reporting-losses-quy_no")
							console.log("this.form.quy_no:" + this.form.quy_no)
							let newData = [];
							if (this.form.quy_no) {
								//补充text
								newData = data.filter((item) => {
									// 过滤如果有对象的区域参数和已经够选择的区域no相同,那么就不用覆盖已经选择的
									return item.QUY_NO === this.form.quy_no
								})
							}

							if (newData.length > 0) {
								console.log("不用重新选择,这是从对象集合种筛出来的区域号相同的对象=>" + JSON.stringify(newData))
								this.quNoList = data.map(v => {
									this.$set(v, 'text', v.QUY_NO)
									this.$set(v, 'value', v.QUY_NO)
									return v
								})
							} else {
								console.log("重新选择,这是库房对应的对象集合,=>" + JSON.stringify(data))
								this.quNoList = data.map(v => {
									this.$set(v, 'text', v.QUY_NO)
									this.$set(v, 'value', v.QUY_NO)
									return v
								})
								//如果切换的区域
								this.form.quy_no = ''
							}
							this.canChangeQuy_no()
						} else {
							this.errContent = res.msg
							this.$u.toast(res.msg);
						}
					});
			},
			// 将区域可选
			canChangeQuy_no() {
				this.notChangeQuyNo = false
			},
			getGzt(loginType) {
				const user_id = uni.getStorageSync('USER_ID')
				const STORAGE_ID = uni.getStorageSync('STORAGE_ID')
				const kuf = "%"
				const gztType = "1"
				const gztId = "%"
				let param = user_id + "," + STORAGE_ID + "," + kuf + "," + gztType + "," + gztId;
				console.log(param)
				this.$u.api.general({
						iv_code: "GETGZTINFO",
						iv_parm: param
					})
					.then(res => {
						// console.log("返回的res:" + JSON.stringify(res))
						let data = res.data
						console.log("getGzt返回的data:" + JSON.stringify(data))
						if (res.success) {
							//补充text
							this.gztList = data.map(v => {
								this.$set(v, 'text', v
									.GZTNAME + "(" + v.GZTID + ")"
								) // https://vuejs.org/v2/guide/reactivity.html
								return v
							})

							// 增加一条特殊的测试数据
							this.gztList.push({
								"text": "DHJ01",
								"WORKLOAD": "4",
								"CENG": "1",
								"GZT_TYPE": "1",
								"ISZCQFP": "N",
								"STORAGEID": "SU3",
								"WORKSTATION_TYPE": "0",
								"LETDOWNFLAG": "1",
								"GZTID": "DHJ01",
								"GZTNAME": "DHJ01测试工作站",
								"KUF_NO": "LHK"
							})
						} else {
							this.$u.toast(res.msg);
						}
					});
			},

		}

	}
</script>
<style lang="scss" scoped>
	@import '../../common/index.scss';
	@import '../../common/base-change.scss';
</style>
